import { ApiCall } from "tsrpc";
import { ClientAction } from "../shared/api_bot/IMassage";
import UserManager from "../core/manage/UserManager";
import client_component from "../component/client_component";
import  { ComType } from "../core/tool/component";
import pos_component from "../component/pos_component";
import { ReqMessage, ResMessage } from "../shared/api_bot/PtlMessage";
import player from "../core/rpg/entity/player";
import rpg_component from "../component/rpg_component";
import sdk from '../core/index';
import SceneManager from "../core/manage/SceneManager";
export default async function (call: ApiCall<ReqMessage, ResMessage>) {
    if(call.req.UserInfo.isBot){
        console.log('不回复bot消息');
        call.succ({ action: ClientAction.none});
        return;
    }
    console.log(`[收到消息:${call.req.ClientInfo.platform}]${call.req.Message.private ? '[私信]' : '[群消息]'}id:${call.req.UserInfo.name}cid:(${call.req.ClientInfo.id})\n${call.req.Message.content}\n----------`);

    let player = call.req._player as player;
    let com_rpg = player.getComponent(ComType.rpg) as rpg_component;
    if(com_rpg.isDie()){
        com_rpg._clientHandler.client_reLive();
    }

    let com_post = player.getComponent(ComType.位置) as pos_component;
    let scene = SceneManager.getScene(com_post.sceneName);
    if (!scene) {
        return
    }
    let _msg = { message: call.req.Message.content, player, call, Message: call.req.Message, ClientInfo: call.req.ClientInfo }
    await scene.tick(_msg);
    scene.analysisIntent(_msg);
    call.succ({ action: ClientAction.none});
}